const express = require('express')
const router = express.Router();
const mysql = require('../db/mysql');
// 有序
const ULID = require('ulid')

// 自定义局部中间件
router.use((req, res, next) => {
    console.log('我是一个user局部中间件')
    next();
})

router.get('/user', (req, res) => {
    console.log(req.url)
    console.log(req.query.name)
    console.log(req.timestamp)
    mysql.query('select 1', (err, results) => {
        console.log(results)
    })
    res.json({'ulid': ULID.ulid()})
})

router.post('/user', (req, res) => {
    console.log(req.body)
    res.send({'code': 0, 'msg': 'success'})
})

router.put('/user', (req, res) => {
    res.send({'code': 0, 'msg': 'success'})
})

router.delete('/user', (req, res) => {
    res.send({'code': 0, 'msg': 'success'})
})

module.exports = router
